package java6;
import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack1 {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek(); 

	public boolean empty(); 

	public int size(); 

}

public class Main1 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayIntegerStack stack = new ArrayIntegerStack(n);
		int m = in.nextInt();
		int[] number = new int[m];
		for (int i = 0; i <= number.length; i++) {
			i = in.nextInt();
			System.out.println(stack.push(i));
		}
		System.out.printf(stack.peek() + ",");
		System.out.printf(stack.empty() + ",");
		System.out.println(stack.size());
		System.out.println(Arrays.toString(stack.arr));
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.printf(stack.peek() + ",");
		System.out.printf(stack.empty() + ",");
		System.out.println(stack.size());
		System.out.println(Arrays.toString(stack.arr));

	}
}

class ArrayIntegerStack1 implements IntegerStack {
	Integer arr[];
	int top=0;

	public ArrayIntegerStack1(int capacity) {
		arr = new Integer[capacity];
	}

	@Override
	public Integer push(Integer item) {
		if (item == null)
			return null;
		if (top == arr.length)
			return null;
		arr[top++] = item;
		return item;
	}

	@Override
	public Integer pop() {
		if (top == 0)
			return null;
		return arr[--top];
	}

	@Override
	public Integer peek() {
		if (top == 0)
			return null;
		return arr[top - 1];
	}

	@Override
	public boolean empty() {
		if (top == 0)
			return true;
		return false;
	}

	@Override
	public int size() {
		return top;
	}
}

